/**
 * Created by jocky on 28/09/2017.
 */
var tradeCostReturnObj = {
    info: function (type, direction) {
        //显示loading
        show_loading_table('tradeCostReturn_table', 9);

        var params = {};
        params.isRender = 0;

        var pageNo_dom = 'tradeCostReturn_pageNo';
        var pageTotal_dom = 'tradeCostReturn_pageTotal';

        params.pageNo = getPageNo(pageNo_dom, pageTotal_dom, type, direction);

        var formObj = $('#trade_cost_return_form');
        $.each(formObj.find('input,select'), function (i, v) {
            var name = $.trim($(v).attr('name'));
            if (name != '') {
                params[name] = $(v).val();
            }
        });

        $.getJSON('/trade-cost-return/info', params, function (json) {
            var sumVolume = parseInt(json.sumVolume);
            var sumTradeCostReturn = parseFloat(json.sumReturn);
            $("#" + pageNo_dom).val(parseInt(json.pageNo));
            $("#" + pageTotal_dom).html(parseInt(json.pageTotal));

            var tr = "";
            $.each(json.lists, function (i, v) {
                var returnFlag = v.return_flag;
                var volume = parseInt(v.volume);
                var tradeCostMy = parseFloat(v.trade_cost_my);
                var tradeCostSub = parseFloat(v.trade_cost_sub);
                var tradeCostReturn = parseFloat(v.trade_cost_return);

                var status = '';
                var color = '';
                var msg = '';
                if (tradeCostReturn > 0) {
                    color = 'red';
                    tradeCostReturn = "+" + tradeCostReturn;

                } else {
                    if (tradeCostReturn < 0) {
                        color = 'green';
                    }
                }

                if (returnFlag == 2) {
                    status = '<i class="fa fa-check" style="color:green;"></i>&nbsp;&nbsp;已返现';
                    msg = "";
                } else {
                    status = '<i class="fa fa-exclamation-circle" style="color:orange;"></i>&nbsp;&nbsp;未返现';
                    msg = "状态码：" + returnFlag;
                }

                tr += "<tr>";
                tr += "<td><a href='javascript:void(0)' onclick=\"traderObj.setForm(" + v.uid + ")\">" + v.clientSN + "</a></td>";
                tr += "<td>" + v.alias + "</td>";
                tr += "<td class='text-right'>" + volume + "</td>";
                tr += "<td class='text-right'>" + tradeCostMy + "</td>";
                tr += "<td class='text-right'>" + tradeCostSub + "</td>";
                tr += "<td class='text-center'>" + convertDate(v.create_time, 1) + "</td>";
                tr += "<td class='text-right' style='color: " + color + "'>" + tradeCostReturn + "</td>";
                tr += "<td class='text-center'>" + status + "</td>";
                tr += "<td class='text-center'>" + msg + "</td>";
                tr += "</tr>";
            });
            var tr_head = "<tr>" +
                "<td><i style='color: red;'>汇总</i></td>" +
                "<td></td>" +
                "<td class='text-right'><i>" + sumVolume + "</i></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td></td>" +
                "<td class='text-right'><i>" + parseFloat(sumTradeCostReturn.toFixed(5)) + "</i></td>" +
                "<td></td>" +
                "<td></td>" +
                "</tr>";

            $("#tradeCostReturn_table").find('tbody').html(tr_head + tr);
        })
    }
};